package org.freedom.imarket.entity.generator;

import java.io.Serializable;
import java.util.Properties;

import org.apache.commons.lang.RandomStringUtils;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IncrementGenerator;
import org.hibernate.type.Type;

public class AlphaNumericIdGenerator extends IncrementGenerator {
	private String length;

	@Override
	public void configure(Type type, Properties params, Dialect dialect)
			throws MappingException {
		// TODO Auto-generated method stub
		length = params.getProperty("length");
	}
	@Override
	public Serializable generate(SessionImplementor implementor, Object obj)
			throws HibernateException {
		return RandomStringUtils.randomAlphanumeric(Integer.parseInt(getLength()));
	}
	public String getLength() {
		return length;
	}
	public void setLength(String length) {
		this.length = length;
	}

}
